/**
 * 批量弹窗控制器
 */
import tem from './index.html'
import './index.less'
import $_fn from '~plugins'
class loanfangCtrl {
  constructor($scope,$rootScope,http,$ui,$state,$location,$timeout) {
    $scope.param = {}
    $scope.redErr = {}
    console.log('$scope.params', $scope.params,$location,$location.path(),$location.search())
    $scope.cancel = function () {
      $rootScope.$uiDirectiveModal.close() //关闭方法
    }
    //警告提示
    $scope.errorToast = function(text) {
      $ui.toast({text:text,type:'warning',position:'center',appendTo:'.wp-container'});
    }
    //成功提示
    $scope.successToast = function(text) {
        $ui.toast({text:text,type:'success',position:'center',appendTo:'.wp-container'});
    }
    $scope.init = function(){
      $scope.sectIds = $_fn._fromCheckValue('ch_id')
      console.log('ids:', $scope.sectIds)
      if($scope.itemData.batchOper && !$scope.sectIds){

        $scope.errorToast('请先选择操作项！')
        $scope.cancel()
      }
    }
    $scope.init()
    $scope.ok=function (state) {

      $scope.param.ids = $scope.params.oid+''
      $scope.param.remark = $scope.params.remark
      http.post('updateOrderBack.do',$scope.param,function (data) {
        if(data.errcode == 1){
          $scope.successToast(data.errmsg)
          $scope.cancel()
          if($rootScope.refreshPage){
            $rootScope.refreshPage(1,{s_id:2,sIds:3})
          }
        }else{
          $scope.errorToast(data.errmsg || '提交失败！')
        }
      })
    }
  }
}


loanfangCtrl.$inject = ['$scope','$rootScope','http','$ui','$state','$location','$timeout','$interval']
module.exports = angular.module('directive.loanfang', []).directive('loanfang', function() {
  return {
    restrict: 'E',
    template: tem,
    replace:true,
    controller: loanfangCtrl,
    scope: {
      itemData: '<'
    },
    link:function(){
      $_fn.clickBind()
    }
  }
}).name